
using CStock;
using System;
using System.Diagnostics;

using NUnit.Framework;
namespace TestCases.StockData
{
	

	/// <summary>Some simple Tests.</summary>
	/// 
	[TestFixture] 
	public class PortfolioTest : ProgramContext_TestCases
	{
		
		IPortfolioFactory portfolioFactory;
        private const string namePortfolio = "Economy_Portfolio";
        private const string nameTrader = "CentralBank";


		[SetUp] 
		public void Init() 
		{
            this.portfolioFactory = new PortfolioFactory();
            portfolioFactory.Create(namePortfolio);

			
		}
		[Test] 
		public void SaveEmptyPortfolio()
		{
			//take care to leave some data in the initialization

            this.portfolioFactory.Serialize();
		}
		[Test] 
		public void Portfolio_Create_And_Save()
		{
			
			
			//create a new item for it
            DataClassTest dtest = new DataClassTest();
            int numberOfShareValues = 200;
            IDataItem dataItem = dtest.CreateDataItem(numberOfShareValues);

			
            dataItem.ID = dtest.DataClassFactory.StockObjectBase.ID;

            dataItem.DataClass = dtest.DataClassFactory.StockObjectBase as IDataClass;


            IPortfolio port = this.portfolioFactory.StockObjectBase as IPortfolio;
            port.DataItems.Items.Add(dataItem);
			//take care to leave some data in the initialization
			this.portfolioFactory.Serialize();
		}

        [Test]
        public void Get_PortfoliosCollection()
        {
            Portfolios perfColl = new Portfolios();
            perfColl.ID = nameTrader;
            perfColl.DeSerialize();
        }
		[Test] 
		public void Get_FromDisk()
		{
			IPortfolio portfolio = new Portfolio();
            portfolio.ID = namePortfolio;
			object o = portfolio;
			portfolio.DeSerialize(ref o);

			portfolio = o as IPortfolio;

			for(int i = 0 ; i < portfolio.DataItems.Count; i++)
			{
				IDataItem di = portfolio.DataItems[i];
				Debug.WriteLine(di.ID);
			}

			//now get the DataClasses out of it:
			for(int i = 0 ; i < portfolio.DataItems.Count; i++)
			{
				IDataItem di = portfolio.DataItems[i];
                
                //with first access to the DataClass - this is deserialized!!
                DataClassDaily ddd = di.DataClass as DataClassDaily;

              

			}


			
		}


	}
}